import React from "react";
import { useHistory } from "react-router-dom";

interface LinkProps {
  to: string;
}

export const UseLink: React.FC<LinkProps> = (props) => {
  const { to, children } = props;
  const history = useHistory();
  const handleLink = (el: React.MouseEvent<HTMLDivElement, MouseEvent>) => {
    el.preventDefault();
    history.push(to);
  };
  return <div onClick={el=> handleLink(el)}>{children}</div>;
};
